package com.jt.sp04orderservice.controller;

import com.jt.sp01.entity.Item;
import com.jt.sp01.entity.Order;
import com.jt.sp01.entity.User;
import com.jt.sp01.service.OrderService;
import com.jt.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * @author Administrator
 */
@RestController
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    @GetMapping("/{orderId}")
    public JsonResult<Order>getOrder(@PathVariable(name = "orderId")String orderId){
        Order order = orderService.getOrder(orderId);
        return JsonResult.ok().data(order);
    }
   //@GetMapping("/add")
    @PostMapping("/add")
    public JsonResult<?>add(){
        orderService.addOrder(new Order("jasguiaehgiawefh",new User(8,null,null), Arrays.asList( new Item[]{
                new Item(1,"商品1",1),
                new Item(2,"商品2",1),
                new Item(3,"商品2",1),
                new Item(4,"商品3",1),
                new Item(5,"商品5",1),
                new Item(6,"商品6",1),
                new Item(7,"商品7",1),
                new Item(8,"商品8",1),



        })));
        return JsonResult.ok().msg("订单添加成功");
    }
    @GetMapping("/favicon.ico")
    public void favicon(){}
}
